package main

import (
	"fmt"
	"strings"
)

// Given a string, return a string with no instance of
// 3 identical consecutive letters, by deleting the minimum
// number of letters

func deleteLetters(s string) string {
	letters := strings.Split(s, "")
	res := letters[0]
	for i := 1; i < len(letters); i++ {
		if letters[i] != letters[i-1] {
			res += letters[i]
		} else {
			cnt := 1
			//same letter
			for i+cnt < len(letters) && letters[i+cnt] == letters[i] {
				cnt++
			}
			if i+cnt < len(letters) {
				res = res + letters[i] + letters[i+cnt]
			} else {
				res = res + letters[i]
			}
			i += cnt
		}
	}
	return res
}

func main() {

	s2 := "xxxtxxx"
	fmt.Println(deleteLetters(s2))
}
